// ========================================================================
// Copyright (c) 2022 ChangYou, All rights reserved.
// http://www.changyou.com/
// 
// Filename:    FoliageMeshInstancesGroup.cs
// Time:        2022-08-22 20:53:58
// Author:      xiangjinbao
// Email:       xiangjinbao@cyou-inc.com
// Version:     v2022.0.1
// Description: FoliageMeshInstancesGroup
// ========================================================================

using System.Collections.Generic;

namespace ProjectTW.Foliage
{
    /// <summary>
    /// 细节对象模型实例组
    /// </summary>
    public class FoliageMeshInstancesGroup
    {
        private List<FoliageMeshInstance> m_TempMeshInstanceList;
        private int m_Count;
        
        public FoliageMeshInstance[] MeshInstanceArray;

        public int Count
        {
            get
            {
                return m_Count;
            }
        }

        public FoliageMeshInstancesGroup()
        {
            MeshInstanceArray = null;
            m_TempMeshInstanceList = new List<FoliageMeshInstance>();
            m_Count = 0;
        }

        public void Add(FoliageMeshInstance instance)
        {
            m_TempMeshInstanceList.Add(instance);
            m_Count = m_TempMeshInstanceList.Count;
        }

        public void Finish()
        {
            MeshInstanceArray = new FoliageMeshInstance[m_TempMeshInstanceList.Count];

            for (int i = 0; i < MeshInstanceArray.Length; i++)
            {
                MeshInstanceArray[i] = m_TempMeshInstanceList[i];
            }
        }

        public void Destroy()
        {
            for (int i = 0; i < MeshInstanceArray.Length; i++)
            {
                MeshInstanceArray[i].Destroy();
            }

            m_TempMeshInstanceList.Clear();
            System.Array.Clear(MeshInstanceArray, 0, MeshInstanceArray.Length);

            m_Count = 0;
        }
    }
}
